package com.stylefeng.guns.modular.pay.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.NotifyRecord;
import com.stylefeng.guns.modular.pay.model.NotifyRecordLog;
import com.stylefeng.guns.modular.pay.service.INotifyRecordLogService;

/**
 * 通知日志控制器
 *
 * @author fengshuonan
 * @Date 2018-08-24 15:20:50
 */
@Controller
@RequestMapping("/notifyRecordLog")
public class NotifyRecordLogController extends BaseController {

    private String PREFIX = "/pay/notifyRecordLog/";

    @Autowired
    private INotifyRecordLogService notifyRecordLogService;

    /**
     * 跳转到通知日志首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "notifyRecordLog.html";
    }

    /**
     * 跳转到添加通知日志
     */
    @RequestMapping("/notifyRecordLog_add")
    public String notifyRecordLogAdd() {
        return PREFIX + "notifyRecordLog_add.html";
    }

    /**
     * 跳转到修改通知日志
     */
    @RequestMapping("/notifyRecordLog_update/{notifyRecordLogId}")
    public String notifyRecordLogUpdate(@PathVariable Integer notifyRecordLogId, Model model) {
        NotifyRecordLog notifyRecordLog = notifyRecordLogService.selectById(notifyRecordLogId);
        model.addAttribute("item",notifyRecordLog);
        LogObjectHolder.me().set(notifyRecordLog);
        return PREFIX + "notifyRecordLog_edit.html";
    }

    /**
     * 获取通知日志列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(NotifyRecordLog notifyRecordLog) {
    	 Page<NotifyRecordLog> page = new PageFactory<NotifyRecordLog>().defaultPage();
         List<NotifyRecordLog> result = notifyRecordLogService.list(page,notifyRecordLog);
         page.setRecords(result);
         return super.packForBT(page);
    }

    /**
     * 新增通知日志
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(NotifyRecordLog notifyRecordLog) {
        notifyRecordLogService.insert(notifyRecordLog);
        return SUCCESS_TIP;
    }

    /**
     * 删除通知日志
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer notifyRecordLogId) {
        notifyRecordLogService.deleteById(notifyRecordLogId);
        return SUCCESS_TIP;
    }

    /**
     * 修改通知日志
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(NotifyRecordLog notifyRecordLog) {
        notifyRecordLogService.updateById(notifyRecordLog);
        return SUCCESS_TIP;
    }

    /**
     * 通知日志详情
     */
    @RequestMapping(value = "/detail/{notifyRecordLogId}")
    @ResponseBody
    public Object detail(@PathVariable("notifyRecordLogId") Integer notifyRecordLogId) {
        return notifyRecordLogService.selectById(notifyRecordLogId);
    }
}
